package com.huibo.common
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	
	import mx.core.FlexGlobals;
	import mx.formatters.DateFormatter;

	public class SysUtil
	{
		
		public var _save_path:String;
		public var _longDateFormat:String;
		public var _shortDateFormat:String;
		public var _log_filename:String
		public var _setDate:String;
		public var _setversion:String;
		
		public var _repeat:Boolean;
		public var _sentence:Boolean;
		public var _onebyone:Boolean;
		public var _mp3root:String;
		public var _textroot:String;
		public var _charset:String;
		
		public function SysUtil()
		{
			init();
		}
		
		
		public function init():void {
			parseFilename("NCE-YYYY-MM.txt");
			var openConfigFile:File = new File(File.applicationDirectory.nativePath+AppContext.CONFIG_FILE);//绑定一个文件
			var stream:FileStream = new FileStream();
			stream.open(openConfigFile,FileMode.READ);//读取文件
			var configXML:XML;
			configXML = new XML(stream.readMultiByte(stream.bytesAvailable,'utf-8'));
			_longDateFormat = configXML.elements("longDateFormat").toString();
			_shortDateFormat = configXML.elements("shortDateFormat").toString();
			_log_filename = parseFilename(configXML.elements("definitionFilename").toString());
			_save_path = configXML.elements("path").toString();
			_setversion = configXML.elements("version").toString();
			_setDate = configXML.elements("date").toString();
			_repeat = Boolean("true"==configXML.elements("repeat").toString());
			_sentence = Boolean("true"==configXML.elements("sentence").toString());
			_onebyone = Boolean("true"==configXML.elements("onebyone").toString());
			_mp3root = configXML.elements("mp3root").toString();
			_textroot = configXML.elements("textroot").toString();
			_charset = configXML.elements("charset").toString();
			if (_save_path.indexOf(":")<=-1) {
				_save_path = File.applicationDirectory.nativePath + "/"+_save_path;
			}
			stream.close();
			openConfigFile = null;		
			//FlexGlobals.topLevelApplication.setTitle(_setversion + " Date:" + _setDate);
		}
		
		
		private function parseFilename(savefilename:String):String {
			var filename:String = "";				
			var dateformat:DateFormatter = new DateFormatter();
			dateformat.formatString = savefilename;
			filename = dateformat.format(new Date());
			return filename;
		}
		
	}
}